import 'dayjs/locale/zh-cn';
import './axios';

import dayjs from 'dayjs';
import { App } from 'vue';

import useAuthStore from '@/stores/auth.store';

dayjs.locale('zh-cn');
export default {
  install: (vm: App) => {
    vm.directive('permission', {
      mounted(el, binding) {
        const authStore = useAuthStore();
        const { value } = binding;
        if (
          ['mumei'].includes(authStore.account)
          && value === 'ROOT'
        ) return;
        if (!authStore.permissions.includes(value)) {
          el.remove();
        }
      },
    });
    vm.directive('role', {
      mounted(el, binding) {
        const authStore = useAuthStore();
        const { value } = binding;
        if (
          ['wangyao03', 'liangnian'].includes(authStore.account)
          && value === 'ROOT'
        ) return;
        if (!authStore.roles.includes(value)) {
          el.remove();
        }
      },
    });
  },
};
